//
// Created by 123 on 2024/12/27.
//

#include "stdio.h"

#include "stdlib.h"

int main083(){
    FILE *src,*dest;
    char ch;
    //打开源文件
    src = fopen("source.txt","r");
    if(src==NULL){
        perror("open error");
        return 1;
    }
    //打开目标文件
    dest = fopen("target.txt","w");
    if(dest == NULL){
        perror("open error");
        //关闭已经打开的源文件
        fclose(src);
        return 1;
    }
    //复制文件内容
    while ((ch = fgetc(src)) != EOF){
        if(fputc(ch,dest) == EOF){
            perror("write file error");
            fclose(src);
            fclose(dest);
            return 1;
        }
    }

    //检查读取是否错误
    if(ferror(src)){
        perror("read src error");
    }
    //关闭文件
    if(fclose(src) != 0){
        perror("close src file error\n");
    }
    if(fclose(dest) != 0){
        perror("close dest file error\n");
    }
    printf("file copy complete!");




    return 0;
}